package com.pcxm.cm.util;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSON;
import com.pcxm.cm.action.SysMenuAction;

public class FastJson {
	private static final Log log = LogFactory.getLog(FastJson.class);
	
	/**
	 * 对象转JSON字符串
	 * @param list
	 * @return
	 * null 返回null  ，空数组返回 []
	 */
	public static String listToJson(List list) {
        String jsonStr = JSON.toJSONString(list);
        log.debug((new StringBuilder()).append("list Json str = ").append(jsonStr).toString());
        return jsonStr;
	}
	
	/**
	 * 转换时间为相应格式
	 * @param date
	 * @param formatString
	 * @return 转换后的String
	 */
	public static String dateFormat(Date date,String formatString) {
		if(null == formatString  || "".equals(formatString)){
			formatString = "yyyy-MM-dd HH:mm:ss.SSS";
		}
		String dateString = JSON.toJSONStringWithDateFormat(date, formatString);
		return dateString;
	}
	
}
